try:
    from xml.etree import cElementTree
except ImportError:
    from elementtree import ElementTree
import gdata.spreadsheet.service
import gdata.service
import atom.service
import gdata.spreadsheet
import atom
import getopt
import sys
import string


class GSpreadsheet:
    # Create google document spreadsheet service
    def __init__(self, email, password):
        self.gd_client = gdata.spreadsheet.service.SpreadsheetsService()
        self.gd_client.email = email
        self.gd_client.password = password
        self.gd_client.source = 'Spreadsheets GDATA'
        self.gd_client.ProgrammaticLogin()
        self.curr_key = ''
        self.curr_wksht_id = ''
        self.list_feed  = None
        
    def Run(self):
        spreadsheets = self.gd_client.GetSpreadsheetsFeed()
        
        si = ''
        for i, entry in enumerate(spreadsheets.entry):
            if entry.title.text == '091110gpci':
                si = spreadsheets.entry[i].id.text.split('/')[-1]
        
        worksheets = self.gd_client.GetWorksheetsFeed(si)
        
        wi = ''
        wi = worksheets.entry[0].id.text.split('/')[-1]
        
        lists = self.gd_client.GetListFeed(si, wi)
        return lists
        #for i, l in enumerate(lists.entry):
        #    print i, l.title.text, l.content.text
        #feed = self.gd_client.GetWorksheetsFeed(wi)

def main():
    sample = GSpreadsheet("hankgong", "Hank209")
    sample.Run()


if __name__ == '__main__':
    main()
